package com.smart_campus.teg.controller;

import com.smart_campus.sys.common.ResultObj;
import com.smart_campus.teg.domain.TegDuty;
import com.smart_campus.teg.service.TegDutyService;
import com.smart_campus.teg.vo.DutyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Alfred
 * @time: 2020/6/30 19:43
 * 值班管理控制器
 */
@RestController
@RequestMapping("duty")
public class DutyController {

    @Autowired
    private TegDutyService tegDutyService;

    /**
     * 查询全部
     * @return
     */
    @RequestMapping("selAllDuty")
    public Object selAllDuty(DutyVo dutyVo){
        return this.tegDutyService.selAllDuty(dutyVo);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("delDuty")
    public ResultObj delDuty(Integer id){
        try {
            this.tegDutyService.deleteByPrimaryKey(id);
            return ResultObj.DELETE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.DELETE_ERROR;
        }
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @RequestMapping("deleteBatchDuty")
    public ResultObj deleteBatchDuty(Integer[] ids){
        try {
            for (Integer id:ids) {
                this.tegDutyService.deleteByPrimaryKey(id);
            }
            return ResultObj.DELETE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.DELETE_ERROR;
        }
    }

    /**
     * 新增值班表
     * @param tegDuty
     * @return
     */
    @RequestMapping("addDuty")
    public ResultObj addDuty(TegDuty tegDuty){
        try {
            this.tegDutyService.insertSelective(tegDuty);
            return ResultObj.ADD_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.ADD_ERROR;
        }
    }

    @GetMapping("getAllStaff")
    public Object getAllStaff(){
        return this.tegDutyService.getAllStaff();
    }

}
